<template>
  <page-header-wrapper :title="false">
    <a-card >
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="销售日期">
                <a-range-picker v-model="queryParam.date" format="YYYY-MM-DD" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="筛选">
                <a-input v-model="value" placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" :loading="loading" @click="handleSearch(queryParam)">查询</a-button>
                <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table ref="table" size="default" rowKey="key" :columns="columns" :data-source="loadData">
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
        <span slot="status" slot-scope="text, record">
          <template>
            <a-tag color="#82af6f" v-if="record?.status == 1">已审核</a-tag>
            <a-tag color="#D15B47" v-else>待审核</a-tag>
          </template>
        </span>
        <span slot="action" slot-scope="text, record">
          <template> <a-tag color="#428bca" @click="handleDetail(record)">详情</a-tag> </template>
        </span>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import moment from 'moment'
import { omit } from 'lodash-es'
import { getOpBusClsStatListUsingPOST } from '@/api/api/tongjibaobiao.ts'
export default {
  name: 'ReportMobileShop',
  data() {
    return {
      mdl: null,
      visible: false,
      activeTabKey: '1',
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      loading: false,
      pagination: {
        total: 0,
      },
      // 查询参数
      queryParam: {
        pageNo: 1,
        pageSize: 10,
        date: [moment().startOf('months').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')],
        queryCondition: '',
        status: '',
      },
      optionParam: {
        pageNo: 1,
        pageSize: 999,
        queryCondition: '',
        status: 1,
      },
      // 表头
      columns: [
        {
          title: '分类',
          dataIndex: 'opBusClsId',
        },
        {
          title: '运营商',
          dataIndex: 'operatorName',
        },
        {
          title: '业务',
          dataIndex: 'opBusinessName',
        },
        {
          title: '业务笔数',
          dataIndex: 'num',
        },
        {
          title: '酬金(元)',
          dataIndex: 'remValue',
        },
        {
          title: '积分',
          dataIndex: 'integral',
        },
        {
          title: '成本(元)',
          dataIndex: 'cost',
        },
        {
          title: '销售额(元)',
          dataIndex: 'price',
        },
        {
          title: '毛利(元)',
          dataIndex: 'grossProfit',
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '180px',
          scopedSlots: { customRender: 'action' },
        },
      ],
      
      // 加载数据方法 必须为 Promise 对象
      loadData: [],
    }
  },
  mounted() {
    this.handleSearch(this.queryParam)
  },
  methods: {
    handleSearch(val) {
      this.loading = true
      const params = {
        ...val,
        startTime: val?.date?.[0] ? moment(val?.date?.[0]).format('YYYY-MM-DD') : null,
        endTime: val?.date?.[1] ? moment(val?.date?.[1]).format('YYYY-MM-DD') : null,
      }
      getOpBusClsStatListUsingPOST({ ...omit(params, ['date']) })
        .then((res) => {
          this.loadData = res.data.list
          this.loading = false
          this.queryParam.pageNo = this.pagination.current
          this.pagination = { ...this.pagination, total: Number(res.data.total) }
        })
        .catch((error) => {
          this.loading = false
          this.$message.error(((error.response || {}).data || {}).msg || '请求出现错误')
        })
    },
    handleDetail(record) {
      this.$router.push({
         path: `/report/Report/mobileDetail/${record?.opBusClsId}` ,
         query: {
          startTime: moment(this.queryParam.date[0]).format('YYYY-MM-DD'),
          endTime: moment(this.queryParam.date[1]).format('YYYY-MM-DD'),
          opBusClsId: record.id,
        },
         })
    },
  },
}
</script>